
package ui.adapter;

import android.content.Context;
import android.net.Uri;

import com.facebook.drawee.view.SimpleDraweeView;

import net.ck.hzq.R;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import Bean.OrderBean;
import Utils.StringUtil;
import base.BaseViewHolder;
import base.SuperBaseAdapter;
import event.CancelOrderEvent;
import event.PayOrderEvent;
import util.SysUtils;


/**
 * 代付款适配器
 * Created by chenjian on 19/2/27.
 */
public class OrderWaitAdapter extends SuperBaseAdapter<OrderBean.DataBean.ItemsBean> {

    List<OrderBean.DataBean.ItemsBean> mData = new ArrayList<>();
    Context mContext;

    public OrderWaitAdapter(Context context, List<OrderBean.DataBean.ItemsBean> data) {
        super(context, data);
        mContext = context;
        mData = data;
    }

    @Override
    protected void convert(BaseViewHolder holder, final OrderBean.DataBean.ItemsBean item, final int position) {
        SimpleDraweeView bg = holder.getView(R.id.listvieworder_img);
        bg.setImageURI(Uri.parse(item.getImgpath()));
        holder.setText(R.id.listvieworder_txt1, "等待买家付款").setText(R.id.listvieworder_txt2, item.getName())
                .setText(R.id.listvieworder_txt3, StringUtil.getFormatPrice(item.getPrice()) + "").setText(R.id.listvieworder_txt4, "x " + item.getNum())
                .setText(R.id.listvieworder_txt5, "共" + item.getNum() + "件商品 合计：¥ " + StringUtil.getFormatPrice(item.getTotalAmount()))
                .setText(R.id.listvieworder_txt6, "取消订单").setText(R.id.listvieworder_txt7, "付款");
        try {
            holder.setText(R.id.order_time, SysUtils.sf.format(new Date(item.getGmtCreate())));
        } catch (Exception e) {
        }
        holder.getView(R.id.listvieworder_txt6).setOnClickListener(v -> {
            EventBus.getDefault().post(new CancelOrderEvent(item.getId()));
        });
        holder.getView(R.id.listvieworder_txt7).setOnClickListener(v -> {
            EventBus.getDefault().post(new PayOrderEvent(item.getId(), item.getTotalAmount()));
        });

    }


    @Override
    protected int getItemViewLayoutId(int position, OrderBean.DataBean.ItemsBean item) {
        return R.layout.listvieworder_item;
    }

}
